{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "512caf3d",
   "metadata": {},
   "source": [
    "-----\n",
    "* 学习人：李许娣\n",
    "* 时间：2021.11.15\n",
    "* 周：12\n",
    "-----"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "38d898cb",
   "metadata": {},
   "source": [
    "## 本周知识点\n",
    "### 1.字典 的一般方法\n",
    "> 1.字典的查询 查询key-> value\n",
    ">> A. 先看字典的key 是否存在 ： in\n",
    ">> B. 查询\n",
    "> 2. 字典的修改\n",
    "> 3. 字典的删除\n",
    "> 4. 字典的增加（dict_name[key] = value）\n",
    "\n",
    "### 2.字典的进阶方法\n",
    "> 1.字典的初始化\n",
    ">> 1. D.fromkeys()\n",
    ">> 2. D.setdefault()\n",
    "\n",
    "### 3.字典的实践（一）课本\n",
    "### 4. 字典的实践（二）课本\n",
    "### 5.字典的实践（三）课外"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "27834542",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1801': 'Cathy', 'stu1802': 'Yang', 'stu1803': 'Kaka', 'stu1806': 'titt', 'stu1809': 'dgf'}\n"
     ]
    }
   ],
   "source": [
    "# 字典的一般方法\n",
    "stu_info = {\n",
    "    \"stu1801\":\"Cathy\",\n",
    "    \"stu1802\":\"Yang\",\n",
    "    \"stu1803\":\"Kaka\",\n",
    "    \"stu1806\":\"titt\",\n",
    "    \"stu1809\":\"dgf\"\n",
    "}\n",
    "print(stu_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "e6e1ead9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Cathy'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字典的查询\n",
    "# 1.直接查找 dict_name[key] 当key不存在时，报错\n",
    "stu_info[\"stu1801\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7ef67fe8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Kaka'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2. 使用get方法查找 D.get(k[.d]) 当key不存在时，返回none 不会报错\n",
    "stu_info.get(\"stu1803\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "02a230ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1801': 'Cathy',\n",
       " 'stu1802': 'Yang',\n",
       " 'stu1803': 'Kaka',\n",
       " 'stu1806': 'titt',\n",
       " 'stu1809': 'dgf',\n",
       " 'stu1804': 'Jojo'}"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字典的修改 & 新增\n",
    "# 1.先查询，查看key是否存在  使用in查询成员\n",
    "# 字典的新增\n",
    "if \"stu1804\" not in stu_info:\n",
    "    stu_info[\"stu1804\"] = \"Jojo\"\n",
    "stu_info "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "53f6a829",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查询1803\n",
    "\"stu1803\" in stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "9e7ba535",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stu1802': 'Yang', 'stu1806': 'titt'}"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 如果key 存在，修改 dict_name[key] = value\n",
    "if \"stu1803\" in stu_info:\n",
    "    stu_info[\"stu1803\"] = \"Yaya\"\n",
    "stu_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "a63d0714",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "删掉stu1803 {'stu1801': 'Cathy', 'stu1802': 'Yang', 'stu1806': 'titt', 'stu1809': 'dgf'}\n",
      "随机删除 {'stu1801': 'Cathy', 'stu1802': 'Yang', 'stu1806': 'titt'}\n",
      "删掉stu1801 {'stu1802': 'Yang', 'stu1806': 'titt'}\n"
     ]
    }
   ],
   "source": [
    "# 字典的删除 D.pop () D.popitem()\n",
    "stu_info.pop('stu1803')\n",
    "print(\"删掉stu1803\",stu_info)\n",
    "stu_info.popitem()\n",
    "# popitem 随机删除\n",
    "print(\"随机删除\",stu_info)\n",
    "del stu_info[\"stu1801\"]\n",
    "print(\"删掉stu1801\",stu_info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "2a5bf952",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:Tuydghj\n",
      "a was found 0 time(s)\n",
      "e was found 0 time(s)\n",
      "i was found 0 time(s)\n",
      "o was found 0 time(s)\n",
      "u was found 1 time(s)\n"
     ]
    }
   ],
   "source": [
    "# 字典的实践（一） 课本P112\n",
    "# 目标： 查询 元音字母是否出现在word文本当中，并且统计出现的次数\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    "\n",
    "# found[\"a\"]=0\n",
    "# found[\"e\"]=0\n",
    "# found[\"i\"]=0\n",
    "# found[\"u\"]=0 \n",
    "for letter in vowels:\n",
    "    # 使用字典的新增 构建初始化字典\n",
    "    found[letter] = 0\n",
    "# 循环用户输入的文本，出现一次元音字母，对应的元音字母加一\n",
    "for letter in word:\n",
    "     if letter in vowels:\n",
    "         found[letter] += 1\n",
    " \n",
    " # print(found.items())\n",
    "for k,v in found.items():\n",
    "    print(k,\"was found\",v,\"time(s)\")# print(found)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a0816d39",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字典的进阶方法： 初始化特定的值 setdefault()\n",
    "# 查询 key 是否出现在字典当中\n",
    "# 1. 出现过，当看不见，不做任何操作\n",
    "# 2.key 未出现，给定key以及value（指定的初始化的值）\n",
    "\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    "\n",
    "# found[\"a\"]=0\n",
    "# found[\"e\"]=0\n",
    "# found[\"i\"]=0\n",
    "# found[\"u\"]=0\n",
    "# 初始化字典\n",
    "found = found.fromkeys(vowels,0)\n",
    "\n",
    "for letter in word:\n",
    "     if letter in vowels:\n",
    "         found[letter] += 1\n",
    " \n",
    " # print(found.items())\n",
    "for k,v in found.items():\n",
    "    print(k,\"was found\",v,\"time(s)\")# print(found)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "b550f53a",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_password = {\n",
    "    \"Cathy\":\"20011122\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "49fa51fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'19910909'"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_password.setdefault(\"Yangyang\",\"19910909\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "976264ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:GJhadjgqq\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'a': 1}"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 优化实践（一）& 实践二 P121\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    "for letter in word:\n",
    "     if letter in vowels:\n",
    "        found.setdefault(letter,0)\n",
    "        found[letter] += 1\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "4e634443",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字典实践（三）\n",
    "people = {}\n",
    "people['Ford'] = {\"Name\":'Ford Prefect',\n",
    "                  \"Gender\":'Male',\n",
    "                  \"Occupation\":'Researcher',\n",
    "                  \"Home Planet\":'Betelgeuse Seven'}\n",
    "people['Arthur'] = {\"Name\":'Arthur Dent',\n",
    "                  \"Gender\":'Male',\n",
    "                  \"Occupation\":'Sandwich-Maker',\n",
    "                  \"Home Planet\":'Earth'}\n",
    "people['Tricia'] = {\"Name\":'Tricia McMillan',\n",
    "                    \"Gender\":'Female',\n",
    "                    \"Occupation\":'Mathematician',\n",
    "                    \"Home Planet\":'Earth'}\n",
    "people['Marvin'] = {\"Name\":'Marvin',\n",
    "                    \"Gender\":'Unknown',\n",
    "                    \"Occupation\":'Paranoid Android',\n",
    "                    \"Home Planet\":'Unknown'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "id": "cf114464",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Ford': {'Name': 'Ford Prefect',\n",
       "  'Gender': 'Male',\n",
       "  'Occupation': 'Researcher',\n",
       "  'Home Planet': 'Betelgeuse Seven'},\n",
       " 'Arthur': {'Name': 'Arthur Dent',\n",
       "  'Gender': 'Male',\n",
       "  'Occupation': 'Sandwich-Maker',\n",
       "  'Home Planet': 'Earth'},\n",
       " 'Tricia': {'Name': 'Tricia McMillan',\n",
       "  'Gender': 'Female',\n",
       "  'Occupation': 'Mathematician',\n",
       "  'Home Planet': 'Earth'},\n",
       " 'Marvin': {'Name': 'Marvin',\n",
       "  'Gender': 'Unknown',\n",
       "  'Occupation': 'Paranoid Android',\n",
       "  'Home Planet': 'Unknown'}}"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "fe110aad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Tricia McMillan'"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取值\n",
    "people['Tricia']['Name']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "854809ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "广州南方学院 = {'status': '1',\n",
    " 'regeocode': {'roads': [{'id': '020F49F0050461206',\n",
    "    'location': '113.678,23.6284',\n",
    "    'direction': '北',\n",
    "    'name': '博学路',\n",
    "    'distance': '7.63232'},\n",
    "   {'id': '020F49F0050462229',\n",
    "    'location': '113.679,23.6245',\n",
    "    'direction': '北',\n",
    "    'name': '老虎形街',\n",
    "    'distance': '445.159'},\n",
    "   {'id': '020F49F0050462451',\n",
    "    'location': '113.677,23.6347',\n",
    "    'direction': '南',\n",
    "    'name': '中山路',\n",
    "    'distance': '708.299'}],\n",
    "  'roadinters': [{'second_name': '中山路',\n",
    "    'first_id': '020F49F0050461206',\n",
    "    'second_id': '020F49F0050462451',\n",
    "    'location': '113.676794,23.634661',\n",
    "    'distance': '708.299',\n",
    "    'first_name': '博学路',\n",
    "    'direction': '南'}],\n",
    "  'formatted_address': '广东省广州市从化区温泉镇博学路',\n",
    "  'addressComponent': {'city': '广州市',\n",
    "   'province': '广东省',\n",
    "   'adcode': '440117',\n",
    "   'district': '从化区',\n",
    "   'towncode': '440117100000',\n",
    "   'streetNumber': {'number': '24号',\n",
    "    'location': '113.677267,23.629149',\n",
    "    'direction': '西北',\n",
    "    'distance': '129.943',\n",
    "    'street': '博学路'},\n",
    "   'country': '中国',\n",
    "   'township': '温泉镇',\n",
    "   'businessAreas': [[]],\n",
    "   'building': {'name': [], 'type': []},\n",
    "   'neighborhood': {'name': [], 'type': []},\n",
    "   'citycode': '020'},\n",
    "  'aois': [],\n",
    "  'pois': [{'id': 'B0FFG4TAF2',\n",
    "    'direction': '东南',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉镇乌土村松浪队5号(近博学路)',\n",
    "    'poiweight': '0.237309',\n",
    "    'name': '广州南方公寓',\n",
    "    'location': '113.678983,23.627778',\n",
    "    'distance': '102.617',\n",
    "    'tel': '13622768437',\n",
    "    'type': '商务住宅;住宅区;住宅小区'},\n",
    "   {'id': 'B0H6FA18J5',\n",
    "    'direction': '东南',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院南侧)',\n",
    "    'poiweight': '0.223065',\n",
    "    'name': '保利半山花园',\n",
    "    'location': '113.679358,23.627672',\n",
    "    'distance': '139.054',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;住宅区'},\n",
    "   {'id': 'B00140TWHT',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '笃行路2',\n",
    "    'poiweight': '0.157653',\n",
    "    'name': '教工住宅1号',\n",
    "    'location': '113.678490,23.630432',\n",
    "    'distance': '222.658',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;住宅小区'},\n",
    "   {'id': 'B0FFHRJDM9',\n",
    "    'direction': '东南',\n",
    "    'businessarea': [],\n",
    "    'address': '中大南方学院南门1号',\n",
    "    'poiweight': '0.256152',\n",
    "    'name': '中南公寓',\n",
    "    'location': '113.680349,23.627573',\n",
    "    'distance': '231.723',\n",
    "    'tel': '13711245345',\n",
    "    'type': '商务住宅;住宅区;住宅小区'},\n",
    "   {'id': 'B0HGD588HJ',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼4号',\n",
    "    'location': '113.677460,23.630490',\n",
    "    'distance': '242.901',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFHZH0IK',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路广州南方学院综合楼内',\n",
    "    'poiweight': '0.17934',\n",
    "    'name': '地下铁',\n",
    "    'location': '113.677941,23.629029',\n",
    "    'distance': '74.1376',\n",
    "    'tel': [],\n",
    "    'type': '餐饮服务;冷饮店;冷饮店'},\n",
    "   {'id': 'B0HGDU76L2',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院2号实验楼',\n",
    "    'location': '113.678211,23.630956',\n",
    "    'distance': '280.003',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFKP838K',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路25',\n",
    "    'poiweight': '0.191742',\n",
    "    'name': '教学楼3号(外国语学院)',\n",
    "    'location': '113.677247,23.630947',\n",
    "    'distance': '298.093',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;高等院校'},\n",
    "   {'id': 'B0HGDU8NLD',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路附近',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院1号实验楼',\n",
    "    'location': '113.678215,23.631370',\n",
    "    'distance': '326.007',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD58UTU',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.191229',\n",
    "    'name': '广州南方学院2号教学楼',\n",
    "    'location': '113.677060,23.631346',\n",
    "    'distance': '346.352',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B00140MR9A',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号',\n",
    "    'poiweight': '0.450402',\n",
    "    'name': '广州南方学院',\n",
    "    'location': '113.679262,23.632583',\n",
    "    'distance': '471.564',\n",
    "    'tel': '020-87828988;020-61787331',\n",
    "    'type': '科教文化服务;学校;高等院校'},\n",
    "   {'id': 'B0HGDU92JD',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': [],\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼1号',\n",
    "    'location': '113.677077,23.631783',\n",
    "    'distance': '391.548',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD592BJ',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道886号广州南方学院内',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院综合楼',\n",
    "    'location': '113.680117,23.631544',\n",
    "    'distance': '392.731',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFKP81F0',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路19号附近',\n",
    "    'poiweight': '0.191742',\n",
    "    'name': '教学楼1号(文学与传媒学院)',\n",
    "    'location': '113.676866,23.631736',\n",
    "    'distance': '393.93',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
    "   {'id': 'B0FFLBEOND',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院)',\n",
    "    'poiweight': '0.190963',\n",
    "    'name': '聚贤楼10号',\n",
    "    'location': '113.681253,23.631036',\n",
    "    'distance': '418.51',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;宿舍'},\n",
    "   {'id': 'B0FFH6K3U9',\n",
    "    'direction': '西北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉镇温泉大道882号广州南方学院H7栋1-5层',\n",
    "    'poiweight': '0.254885',\n",
    "    'name': '广州中大南方招待所',\n",
    "    'location': '113.676330,23.631332',\n",
    "    'distance': '378.102',\n",
    "    'tel': '020-61787222',\n",
    "    'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
    "   {'id': 'B0HGD58NF8',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院新综合楼2层',\n",
    "    'poiweight': '0.191229',\n",
    "    'name': '广州南方学院达人书院',\n",
    "    'location': '113.679041,23.632392',\n",
    "    'distance': '446.366',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
    "   {'id': 'B0FFKUVYWV',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '保利桃花源',\n",
    "    'poiweight': '0.273168',\n",
    "    'name': '广州和风庭阿七度假别墅',\n",
    "    'location': '113.681736,23.630569',\n",
    "    'distance': '424.35',\n",
    "    'tel': '18681565305',\n",
    "    'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
    "   {'id': 'B0HGDU99RM',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院内',\n",
    "    'poiweight': '0.257947',\n",
    "    'name': '广州南方学院图书馆',\n",
    "    'location': '113.679177,23.632762',\n",
    "    'distance': '489.331',\n",
    "    'tel': '020-61787368;020-61787371',\n",
    "    'type': '科教文化服务;图书馆;图书馆'},\n",
    "   {'id': 'B0HGDU92JC',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路附近',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院4号实验楼',\n",
    "    'location': '113.679963,23.632652',\n",
    "    'distance': '498.883',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0FFL7C054',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉镇博学路882号(广州南方学院商业中心1层)',\n",
    "    'poiweight': '0.317505',\n",
    "    'name': '广州U优森特酒店',\n",
    "    'location': '113.679226,23.632528',\n",
    "    'distance': '464.819',\n",
    "    'tel': '15813395296',\n",
    "    'type': '住宿服务;住宿服务相关;住宿服务相关'},\n",
    "   {'id': 'B0FFG8CSEK',\n",
    "    'direction': '东北',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院)',\n",
    "    'poiweight': '0.185371',\n",
    "    'name': 'L5员工宿舍',\n",
    "    'location': '113.682583,23.631487',\n",
    "    'distance': '554.129',\n",
    "    'tel': [],\n",
    "    'type': '商务住宅;住宅区;宿舍'},\n",
    "   {'id': 'B0HGD58FR2',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '广州南方学院',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼9号',\n",
    "    'location': '113.679747,23.633032',\n",
    "    'distance': '532.163',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HG5Z9JNK',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路',\n",
    "    'poiweight': '0.221553',\n",
    "    'name': '广州南方学院教学楼7号',\n",
    "    'location': '113.678600,23.633330',\n",
    "    'distance': '544.868',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD599JM',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院第11教学楼',\n",
    "    'location': '113.680037,23.633173',\n",
    "    'distance': '556.036',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0GUJYPEG2',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882号广州南方学院内博学路6号之3',\n",
    "    'poiweight': '0.216026',\n",
    "    'name': '怒烤烤串(从化店)',\n",
    "    'location': '113.677160,23.632910',\n",
    "    'distance': '510.112',\n",
    "    'tel': [],\n",
    "    'type': '餐饮服务;中餐厅;特色/地方风味餐厅'},\n",
    "   {'id': 'B0HGDU6Z41',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '温泉大道882',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼6号',\n",
    "    'location': '113.678424,23.633710',\n",
    "    'distance': '586.331',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'},\n",
    "   {'id': 'B0HGD580NZ',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '博学路7号附近',\n",
    "    'poiweight': '0.285712',\n",
    "    'name': '广州南方学院惟贤门',\n",
    "    'location': '113.678437,23.633721',\n",
    "    'distance': '587.601',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;高等院校'},\n",
    "   {'id': 'B0HGDU7T1K',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '从莞深高速(广州南方学院)',\n",
    "    'poiweight': '0.191229',\n",
    "    'name': '广州南方学院教学楼10号',\n",
    "    'location': '113.680125,23.633492',\n",
    "    'distance': '592.504',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;科教文化场所;科教文化场所'},\n",
    "   {'id': 'B0HGDU76L1',\n",
    "    'direction': '北',\n",
    "    'businessarea': [],\n",
    "    'address': '中山路与博学路交叉口东南150米',\n",
    "    'poiweight': '0.221662',\n",
    "    'name': '广州南方学院教学楼5号',\n",
    "    'location': '113.678046,23.633982',\n",
    "    'distance': '616.848',\n",
    "    'tel': [],\n",
    "    'type': '科教文化服务;学校;学校'}]},\n",
    " 'info': 'OK',\n",
    " 'infocode': '10000'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "659c3c5d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['status', 'regeocode', 'info', 'infocode'])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "广州南方学院.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "32c10db3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1'"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "广州南方学院['status']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "7ee85b6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['roads', 'roadinters', 'formatted_address', 'addressComponent', 'aois', 'pois'])"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "广州南方学院['regeocode'].keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "dec01ff6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'id': 'B0HGD588HJ', 'direction': '北', 'businessarea': [], 'address': '博学路', 'poiweight': '0.221662', 'name': '广州南方学院教学楼4号', 'location': '113.677460,23.630490', 'distance': '242.901', 'tel': [], 'type': '科教文化服务;学校;学校'}\n"
     ]
    }
   ],
   "source": [
    "#  第一题\n",
    "# 列表 ： 存相同数据结构类型数据  but usually the items all have the same type\n",
    "pois_list = 广州南方学院['regeocode']['pois']\n",
    "for i in pois_list:\n",
    "    if i[\"id\"] == 'B0HGD588HJ':\n",
    "        print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3aa2f25",
   "metadata": {},
   "source": [
    "## 课后实践:\n",
    "* 请找出 id 为 'B0HGD588HJ' 的 信息(第一题如上)\n",
    "* 请找出所有的 pois 中的字典元素 的 id，存到一个id列表中\n",
    "* 请找出所有的 pois 中的字典元素 的 name，存到一个 id 列表中\n",
    "* 请找出所有的 name 以及 location 做一个字典 （name_dict = {name1:location1 , name2:location2...}）\n",
    "* 请找出所有 含有 'tel' 的元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "8a48b748",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "B0FFG4TAF2\n",
      "B0H6FA18J5\n",
      "B00140TWHT\n",
      "B0FFHRJDM9\n",
      "B0HGD588HJ\n",
      "B0FFHZH0IK\n",
      "B0HGDU76L2\n",
      "B0FFKP838K\n",
      "B0HGDU8NLD\n",
      "B0HGD58UTU\n",
      "B00140MR9A\n",
      "B0HGDU92JD\n",
      "B0HGD592BJ\n",
      "B0FFKP81F0\n",
      "B0FFLBEOND\n",
      "B0FFH6K3U9\n",
      "B0HGD58NF8\n",
      "B0FFKUVYWV\n",
      "B0HGDU99RM\n",
      "B0HGDU92JC\n",
      "B0FFL7C054\n",
      "B0FFG8CSEK\n",
      "B0HGD58FR2\n",
      "B0HG5Z9JNK\n",
      "B0HGD599JM\n",
      "B0GUJYPEG2\n",
      "B0HGDU6Z41\n",
      "B0HGD580NZ\n",
      "B0HGDU7T1K\n",
      "B0HGDU76L1\n"
     ]
    }
   ],
   "source": [
    "# 第二题\n",
    "for i in 广州南方学院['regeocode']['pois']:\n",
    "    print(i[\"id\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "7e979b2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方公寓\n",
      "保利半山花园\n",
      "教工住宅1号\n",
      "中南公寓\n",
      "广州南方学院教学楼4号\n",
      "地下铁\n",
      "广州南方学院2号实验楼\n",
      "教学楼3号(外国语学院)\n",
      "广州南方学院1号实验楼\n",
      "广州南方学院2号教学楼\n",
      "广州南方学院\n",
      "广州南方学院教学楼1号\n",
      "广州南方学院综合楼\n",
      "教学楼1号(文学与传媒学院)\n",
      "聚贤楼10号\n",
      "广州中大南方招待所\n",
      "广州南方学院达人书院\n",
      "广州和风庭阿七度假别墅\n",
      "广州南方学院图书馆\n",
      "广州南方学院4号实验楼\n",
      "广州U优森特酒店\n",
      "L5员工宿舍\n",
      "广州南方学院教学楼9号\n",
      "广州南方学院教学楼7号\n",
      "广州南方学院第11教学楼\n",
      "怒烤烤串(从化店)\n",
      "广州南方学院教学楼6号\n",
      "广州南方学院惟贤门\n",
      "广州南方学院教学楼10号\n",
      "广州南方学院教学楼5号\n"
     ]
    }
   ],
   "source": [
    "# 第三题\n",
    "for i in 广州南方学院['regeocode']['pois']:\n",
    "    print(i[\"name\"])\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "9fa1ce2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('广州南方公寓', '113.678983,23.627778')\n",
      "('保利半山花园', '113.679358,23.627672')\n",
      "('教工住宅1号', '113.678490,23.630432')\n",
      "('中南公寓', '113.680349,23.627573')\n",
      "('广州南方学院教学楼4号', '113.677460,23.630490')\n",
      "('地下铁', '113.677941,23.629029')\n",
      "('广州南方学院2号实验楼', '113.678211,23.630956')\n",
      "('教学楼3号(外国语学院)', '113.677247,23.630947')\n",
      "('广州南方学院1号实验楼', '113.678215,23.631370')\n",
      "('广州南方学院2号教学楼', '113.677060,23.631346')\n",
      "('广州南方学院', '113.679262,23.632583')\n",
      "('广州南方学院教学楼1号', '113.677077,23.631783')\n",
      "('广州南方学院综合楼', '113.680117,23.631544')\n",
      "('教学楼1号(文学与传媒学院)', '113.676866,23.631736')\n",
      "('聚贤楼10号', '113.681253,23.631036')\n",
      "('广州中大南方招待所', '113.676330,23.631332')\n",
      "('广州南方学院达人书院', '113.679041,23.632392')\n",
      "('广州和风庭阿七度假别墅', '113.681736,23.630569')\n",
      "('广州南方学院图书馆', '113.679177,23.632762')\n",
      "('广州南方学院4号实验楼', '113.679963,23.632652')\n",
      "('广州U优森特酒店', '113.679226,23.632528')\n",
      "('L5员工宿舍', '113.682583,23.631487')\n",
      "('广州南方学院教学楼9号', '113.679747,23.633032')\n",
      "('广州南方学院教学楼7号', '113.678600,23.633330')\n",
      "('广州南方学院第11教学楼', '113.680037,23.633173')\n",
      "('怒烤烤串(从化店)', '113.677160,23.632910')\n",
      "('广州南方学院教学楼6号', '113.678424,23.633710')\n",
      "('广州南方学院惟贤门', '113.678437,23.633721')\n",
      "('广州南方学院教学楼10号', '113.680125,23.633492')\n",
      "('广州南方学院教学楼5号', '113.678046,23.633982')\n"
     ]
    }
   ],
   "source": [
    "# 第四题\n",
    "vowels= {}\n",
    "for i in 广州南方学院['regeocode']['pois']:\n",
    "    vowels = i[\"name\"],i[\"location\"]\n",
    "    print(vowels)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "5dae0228",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13622768437\n",
      "[]\n",
      "[]\n",
      "13711245345\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "020-87828988;020-61787331\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "020-61787222\n",
      "[]\n",
      "18681565305\n",
      "020-61787368;020-61787371\n",
      "[]\n",
      "15813395296\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "# 第五题\n",
    "# 第二题\n",
    "for i in 广州南方学院['regeocode']['pois']:\n",
    "    print(i[\"tel\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e55bfd34",
   "metadata": {},
   "source": [
    "|字典的方法    | 具体使用 | 注意事项 | 使用结果|\n",
    "|---------------|----------|----------|---------|\n",
    "|pop| dict_name.pop(\"key\") | key存在  | 删除对应的key |\n",
    "|del| del dict_name[\"key\"] | key存在  | 删除对应的key |\n",
    "|[\"\"]| dict_name[\"key\"] | key存在;当key不存在时，报错  | 查询对应key的值 |\n",
    "|get| dict_name.get(\"key\") | 当key不存在时，返回none 不会报错  | 查询对应的key |\n",
    "|新增/修改| dict_name[\"key\"] = value |如果key存在，则修改键值对;如果key不存在，会新增加键值对  | 增加或修改对应的key |\n",
    "|popitem| dict_name.popitem() | key存在  | 随机删除字典中的key |\n",
    "|len| len(dict_name) | 无  | 统计key数量 |\n",
    "|update| dict_name.update(另一个字典名) | 如果被合并的字典包括原来的键值对时，原来的键值对值会被覆盖  | 合并字典（两个字典合二为一） |\n",
    "|clear| dict_name.clear() | key存在  | 清空字典 |\n",
    "|copy|  新字典名 = dict_name.copy() | 有新的地址，指向的不是同一个字典，与a=b赋值不同  | 拷贝形成新的一模一样的字典 |\n",
    "|setdefault| dict_name.pop(\"key\") | 括号里的key不存在  | 字典里增加空的key |\n",
    "|fromkeys| 新字典名 = dict.fromkeys(value) |key不同，value相同  | 创建新的字典|\n",
    "|items| dict_name.items() | key存在  | 以列表返回可遍历的（键值）元组数组 |\n",
    "|keys| dict_name.keys() | key存在  | 罗列字典所有的key |\n",
    "|values| dict_name.values() | key存在  | 罗列字典中全部的values |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "d9407eeb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "xiaoming\n",
      "增加 {'name': 'xiaoming', 'age': 20, 'height': 1.8, 'hobby': '唱歌'}\n",
      "修改 {'name': 'xiaoming', 'age': 30, 'height': 1.8, 'hobby': '唱歌'}\n",
      "删掉体重 {'name': 'xiaoming', 'age': 30, 'hobby': '唱歌'}\n",
      "删掉名字 {'age': 30, 'hobby': '唱歌'}\n",
      "随机删除 {'age': 30}\n",
      "1\n",
      "合并 {'age': 30, 'score': 99, 'name': 'xiaohong'}\n",
      "copy之后的新字典题： {'age': 30, 'score': 99, 'name': 'xiaohong'}\n",
      "{'age': '杨洋老婆是我', 'score': '杨洋老婆是我', 'name': '杨洋老婆是我', 'hobby': '杨洋老婆是我'}\n",
      "dict_items([('age', 30), ('score', 99), ('name', 'xiaohong'), ('hobby', None)])\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "dict_values([30, 99, 'xiaohong', None])"
      ]
     },
     "execution_count": 129,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xiaoming = {\"name\":\"xiaoming\",\n",
    "           \"age\": 20,\n",
    "           \"height\": 1.8}\n",
    "# 1.取值 [\"\"]\n",
    "#在取值时，如果key不存在，程序会报错\n",
    "# print(xiaoming[\"name12\"])\n",
    "print(xiaoming[\"name\"])\n",
    "# 2.增加或修改\n",
    "# 如果key不存在，会新增加键值对\n",
    "xiaoming[\"hobby\"]=\"唱歌\"\n",
    "print(\"增加\",xiaoming)\n",
    "# 如果key存在，则修改键值对\n",
    "xiaoming[\"age\"]=30\n",
    "print(\"修改\",xiaoming)\n",
    "# 3.删除 pop/del\n",
    "xiaoming.pop(\"height\")\n",
    "print(\"删掉体重\",xiaoming)\n",
    "del xiaoming[\"name\"]\n",
    "print(\"删掉名字\",xiaoming)\n",
    "# 3.1随机删除\n",
    "xiaoming.popitem()\n",
    "print(\"随机删除\",xiaoming)\n",
    "# 4.统计键值对数量 len\n",
    "print(len(xiaoming))\n",
    "# 5.合并字典 update\n",
    "# 注意：如果被合并的字典包括原来的键值对时，原来的键值对值会被覆盖\n",
    "xh = {\"score\" :99,\n",
    "     \"name\": \"xiaohong\"}\n",
    "xiaoming.update(xh)\n",
    "print(\"合并\",xiaoming)\n",
    "# 6.清空字典\n",
    "# xiaoming.clear()\n",
    "# print(\"清空\",xiaoming)\n",
    "# 7.拷贝字典 copy\n",
    "# 有新的地址，指向的不是同一个字典\n",
    "ti = xiaoming.copy()\n",
    "print(\"copy之后的新字典题：\",ti)\n",
    "# 8. 增加内容 setdefault\n",
    "ti.setdefault(\"hobby\")\n",
    "ti\n",
    "# 9. get 查询字典\n",
    "ti.get(\"age\")\n",
    "# 10. 创建新字典fromkeys\n",
    "yu = dict.fromkeys(ti,'杨洋老婆是我')\n",
    "print(yu)\n",
    "# 11. items() 以列表返回可遍历的（键值）元组数组\n",
    "print(ti.items())\n",
    "# 12. 字典中的键值对 key 种类\n",
    "ti.keys()\n",
    "# 13. 查询字典中的values\n",
    "ti.values()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0272c15d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}